package 代码记录.指定公司代码练习记录.华为_2024.分值200;

import java.util.*;

/**
 * @author zx
 * @create 2024-02-16 14:47
 * 全排列(能看懂代码，但是自己应该做不出来)
 */
public class 考古学家_28 {
    public static final TreeSet<String> set = new TreeSet<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String in = sc.nextLine();
        String[] arr = in.split(" ");
        solve(0, arr);
        for (String str : set) {
            System.out.println(str);
        }
    }

    public static void solve(int index, String[] arr) {
        if (index == arr.length) {
            StringBuilder sb = new StringBuilder();
            for (String str : arr) {
                sb.append(str);
            }
            set.add(sb.toString());
            return;
        }
        for (int i = index; i < arr.length; ++i) {
            swap(arr, i, index);
            solve(index + 1, arr);
            swap(arr, i, index);
        }
    }

    public static void swap(String[] arr, int i, int j) {
        String temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
